import eventHub from "@/utils/event-hub";
export const setItem = (prop, data) => {
	let isObject = typeof data === "object";
	uni.setStorageSync(prop, isObject ? JSON.stringify(data) : data);
	eventHub.emit(
		`update${prop.slice(0, 1).toUpperCase()}${prop.slice(1)}`,
		data
	);
};
export const getItem = (prop) => {
	try {
		const originData = uni.getStorageSync(prop);
		let isObject = originData && (originData + '').indexOf("{") !== -1;
		const result = isObject ? JSON.parse(originData) : originData;
		return result;
	} catch (e) {
		console.log(e);
		return e;
	}
};
export default {
	setItem,
	getItem,
};